package com.android.home.fragment;

import android.view.ViewGroup;
import com.android.common.base.rv.BaseMultiSelectRvFragment;
import com.android.common.base.rv.BaseRvAdapter;
import com.android.common.base.rv.BaseRvHolder;
import com.android.home.R;
import com.android.home.adapter.holder.MsgListHolder;
import com.android.home.mvp.model.home.MultiSelectListBean;
import com.android.home.mvp.present.home.HomePresent;

public class MultiSelectRvFragment extends BaseMultiSelectRvFragment<MultiSelectListBean.RowsBean> {
    private HomePresent present;

    @Override
    protected void onInitView() {
        super.onInitView();
        present = new HomePresent(this);
    }

    @Override
    protected boolean onNeedToolBar() {
        return false;
    }

    @Override
    protected BaseRvAdapter<MultiSelectListBean.RowsBean> initAdapter(){
        mAdapter = new BaseRvAdapter<MultiSelectListBean.RowsBean>(this.getContext()){
            @Override
            protected BaseRvHolder<MultiSelectListBean.RowsBean> createDataViewHolder(ViewGroup parent, int viewType) {
                MsgListHolder holder = new MsgListHolder(mLayoutInflater.inflate(R.layout.item_msg_list,parent,false));
                holder.setChildViewCheckedListener((view, position, isChecked) ->
                    onCheckedListener(view,position,isChecked));
                return holder;
            }
        };
        return mAdapter;
    }

    @Override
    protected void onLoadData() {
        super.onLoadData();
        showProgress();
        present.getMultiSelectList();
    }

    @Override
    public <D> void onSucceed(D d, String methodName) {
        super.onSucceed(d, methodName);
        if (HomePresent.GET_MULTI_SELECT_LIST.equals(methodName)
            && d instanceof MultiSelectListBean){
            MultiSelectListBean bean = (MultiSelectListBean)d;
            refreshOrLoadSuccess(bean.getRows(),bean.getTotal());
        }
    }
}
